<template>
    <div class="position">
        <!-- <NavTitle :is-more="false" title="仓位" :icon="Icon"></NavTitle> -->
        <div class="p-nav">
            <NavTitle :is-more="false" :title="$t('message.Position.a')"></NavTitle>
            <!-- <JButtons :list="market" v-model="curMarket" @change="onMarket"></JButtons> -->
            <JButtons :list="timer" v-model="curTimer" @change="onTimer"></JButtons>
        </div>
        <div class="tb-list">
            <Table1
                v-for="i in tables"
                :key="i.title"
                :type="i.type"
                :symbol="coin"
                :period="curTimer.value"
                :timestampKey="i.timestampKey"
                :title="i.title"
                :desc="i.desc"
                :url="i.url"
                :items="i.items"
            >
            </Table1>
        </div>
    </div>
</template>

<script lang="ts" setup>
import { ref, reactive, onMounted, computed } from "vue";
import { useAccount } from "@/stores/account";
import NavTitle from "@/components/NavTitle/index.vue";
import JButtons from "@/components/j-buttons/index.vue";
import Icon from "@/assets/doar.png";
// import { get } from "@/comm/request";
// import { URL_TOTAL_RATIO } from "@/comm/api";
import { useKline } from "@/stores/kline";

import Table1 from "./table1.vue";
import Table2 from "./table2.vue";
import { URL_ACCOUNT_RATIO, URL_AUTO_RATIO, URL_CONTRACT_HIST, URL_FUNDING_RATE, URL_POSITION_RATIO, URL_TOTAL_RATIO } from "@/comm/api";
import { useRoute } from "vue-router";
import i18n from "@/locals";
import { TableType } from "./tabs/ClassifySet";

const account = useAccount();
const myAccount = ref("1221223@google.com");
const kline = useKline();
const route = useRoute();

const coin = ref(route.params.id + "");

const onFacebook = () => {
    account.changePopBindFacebook(true);
};

const tables = reactive([
    // {
    //     title: "大户持仓量多空比",
    //     url: URL_POSITION_RATIO,
    //     desc: "大户持仓量多空比大户持仓量多空比大户持仓量多空比",
    //     items: [{ tip: "多仓账户比例", key: "longAccount", axis: "比值" }, { tip: "空仓账户比例", key: "longShortRatio", axis: "比值" }],
    //     timestampKey: "timestamp",
    //     type: 1
    // },
    {
        title: i18n.global.t("message.Position.table.a.a"),
        url: URL_POSITION_RATIO,
        desc: i18n.global.t("message.Position.table.a.b"),
        items: [
            { tip: i18n.global.t("message.Position.table.a.c"), key: "longAccount", axis: "比值" },
            { tip: i18n.global.t("message.Position.table.a.d"), key: "longShortRatio", axis: "比值" }
        ],
        timestampKey: "timestamp",
        type: 0
    },
    // {
    //     title: "大户账户数多空比",
    //     url: URL_ACCOUNT_RATIO,
    //     desc: "大户持仓量多空比大户持仓量多空比大户持仓量多空比",
    //     items: [{ tip: "多仓账户比例", key: "longAccount", axis: "比值" }, { tip: "空仓账户比例", key: "longShortRatio", axis: "比值" }],
    //     timestampKey: "timestamp",
    //     type: 1
    // },
    {
        title: i18n.global.t("message.Position.table.b.a"),
        url: URL_ACCOUNT_RATIO,
        desc: i18n.global.t("message.Position.table.b.b"),
        items: [
            { tip: i18n.global.t("message.Position.table.b.c"), key: "longAccount", axis: "比值" },
            { tip: i18n.global.t("message.Position.table.b.d"), key: "longShortRatio", axis: "比值" }
        ],
        timestampKey: "timestamp",
        type: 1
    },
    // {
    //     title: "合约主动买卖量",
    //     url: URL_AUTO_RATIO,
    //     desc: "大户持仓量多空比大户持仓量多空比大户持仓量多空比",
    //     items: [{ tip: "买入总量", key: "buyVol", axis: "数量" }, { tip: "卖出总量", key: "sellVol", axis: "数量" }],
    //     timestampKey: "timestamp",
    //     type: 0
    // },
    {
        title: i18n.global.t("message.Position.table.c.a"),
        url: URL_AUTO_RATIO,
        desc: i18n.global.t("message.Position.table.c.b"),
        items: [
            { tip: i18n.global.t("message.Position.table.c.c"), key: "buyVol", axis: i18n.global.t("message.Position.table.c.e") },
            { tip: i18n.global.t("message.Position.table.c.d"), key: "sellVol", axis: i18n.global.t("message.Position.table.c.f") }
        ],
        timestampKey: "timestamp",
        type: 2
    },
    // {
    //     title: "合约持仓量",
    //     url: URL_CONTRACT_HIST,
    //     desc: "大户持仓量多空比大户持仓量多空比大户持仓量多空比",
    //     items: [{ tip: "持仓总量", key: "sumOpenInterest", axis: "数量" }, { tip: "持仓总价值", key: "sumOpenInterestValue", axis: "价值" }],
    //     timestampKey: "timestamp",
    //     type: 0
    // },
    {
        title: i18n.global.t("message.Position.table.d.a"),
        url: URL_CONTRACT_HIST,
        desc: i18n.global.t("message.Position.table.d.b"),
        items: [
            { tip: i18n.global.t("message.Position.table.d.c"), key: "sumOpenInterest", axis: i18n.global.t("message.Position.table.d.e") },
            { tip: i18n.global.t("message.Position.table.d.d"), key: "sumOpenInterestValue", axis: i18n.global.t("message.Position.table.d.f") }
        ],
        timestampKey: "timestamp",
        type: 3
    },
    // {
    //     title: "多空持仓人数比",
    //     url: URL_TOTAL_RATIO,
    //     desc: "大户持仓量多空比大户持仓量多空比大户持仓量多空比",
    //     items: [{ tip: "看多人数比", key: "longAccount", axis: "比值" }, { tip: "看空人数比", key: "shortAccount", axis: "比值" }],
    //     timestampKey: "timestamp",
    //     type: 1
    // },
    {
        title: i18n.global.t("message.Position.table.e.a"),
        url: URL_TOTAL_RATIO,
        desc: i18n.global.t("message.Position.table.e.b"),
        items: [
            { tip: i18n.global.t("message.Position.table.e.c"), key: "longAccount", axis: "比值" },
            { tip: i18n.global.t("message.Position.table.e.d"), key: "shortAccount", axis: "比值" }
        ],
        timestampKey: "timestamp",
        type: 4
    },
    // {
    //     title: "资金费率",
    //     url: URL_FUNDING_RATE,
    //     desc: "大户持仓量多空比大户持仓量多空比大户持仓量多空比",
    //     items: [{ tip: "资金费率", key: "fundingRate", axis: "比值" }],
    //     timestampKey: "fundingTime",
    //     type: 2
    // },
    {
        title: i18n.global.t("message.Position.table.f.a"),
        url: URL_FUNDING_RATE,
        desc: i18n.global.t("message.Position.table.f.b"),
        items: [{ tip: i18n.global.t("message.Position.table.f.c"), key: "fundingRate", axis: "" }],
        timestampKey: "fundingTime",
        type: 5
    }
]);

onMounted(async () => {
    // let res:any = await get(URL_TOTAL_RATIO, {
    //     symbol: kline.curCoin.symbol,
    //     period: curTimer.value.value
    // });
    // console.log(res, "res");
    // res.data = []
});

const items = ref([
    {
        // title: "主頁",
        title: i18n.global.t("message.Global.Home"),
        disabled: false,
        href: "/"
    },
    {
        // title: "獎勵中心",
        title: i18n.global.t("message.Global.child.b"),
        disabled: true,
        href: ""
    }
]);

const market = ref([
    // {
    //     label: "所有",
    //     value: null
    // },
    {
        label: "Binance",
        value: "Binance"
    }
    // {
    //     label: "OKX",
    //     value: "OKX"
    // },
]);
const curMarket = ref(market.value[0]);
const onMarket = () => {
    console.log(curMarket.value);
};
const timer = ref([
    {
        // label: "5分钟",
        label: i18n.global.t("message.Position.times.a"),
        value: "MN5"
    },
    {
        // label: "15分钟",
        label: i18n.global.t("message.Position.times.b"),
        value: "MN15"
    },
    {
        // label: "30分钟",
        label: i18n.global.t("message.Position.times.c"),
        value: "MN30"
    },
    {
        // label: "1小时",
        label: i18n.global.t("message.Position.times.d"),
        value: "H1"
    },
    {
        // label: "2小时",
        label: i18n.global.t("message.Position.times.e"),
        value: "H2"
    },
    {
        // label: "4小时",
        label: i18n.global.t("message.Position.times.f"),
        value: "H4"
    },
    {
        // label: "6小时",
        label: i18n.global.t("message.Position.times.g"),
        value: "H6"
    },
    {
        // label: "12小时",
        label: i18n.global.t("message.Position.times.h"),
        value: "H12"
    },
    {
        // label: "1天",
        label: i18n.global.t("message.Position.times.i"),
        value: "D1"
    }
]);
const curTimer = ref(timer.value[0]);
const onTimer = () => {
    console.log(curTimer.value);
};
</script>

<style lang="less" scoped>
@import url("./index.less");
</style>
